package com.lihao.wanandroid.ui.navigation

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lihao.wanandroid.R
import com.lihao.wanandroid.data.model.NavigationResponse

/**
 * 导航分类标题适配器
 */
class NaviTitleAdapter :
    BaseQuickAdapter<NavigationResponse, BaseViewHolder>(R.layout.item_nav_classify) {

    override fun convert(holder: BaseViewHolder, item: NavigationResponse) {
        holder.setText(R.id.tvTitle, item.name)
        if (item.isSelected) {
            holder.setTextColorRes(R.id.tvTitle, R.color.colorPrimary)
            holder.setBackgroundResource(R.id.parentView, R.color.wall)
            holder.setGone(R.id.ivIndicator, false)
        } else {
            holder.setTextColorRes(R.id.tvTitle, R.color.text_dark)
            holder.setBackgroundResource(R.id.parentView, R.color.white)
            holder.setGone(R.id.ivIndicator, true)
        }
    }

    fun setSelected(position: Int) {
        for (item in data) {
            item.isSelected = false
        }
        data[position].isSelected = true
        notifyDataSetChanged()
    }
}